package cn.fzhui.util;

import java.util.List;

/**
 * 分页
 */
public class PageList<E> {

    private List<E> list;

    private int perPage; // 每页记录数

    private long totalNumber; // 总记录数

    private long totalPageNumber; // 总页数

    private int currentPage; // 当前页数

    public long getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(long totalNumber) {
        this.totalNumber = totalNumber;
        this.setTotalPageNumber((totalNumber / this.getPerPage()) + 1);
    }

    public long getTotalPageNumber() {
        return totalPageNumber;
    }

    public void setTotalPageNumber(long totalPageNumber) {
        this.totalPageNumber = totalPageNumber;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPerPage() {
        return perPage;
    }

    public void setPerPage(int perPage) {
        this.perPage = perPage;
    }

    public List<E> getList() {
        return list;
    }

    public void setList(List<E> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageList{" +
                "list=" + list +
                ", perPage=" + perPage +
                ", totalNumber=" + totalNumber +
                ", totalPageNumber=" + totalPageNumber +
                ", currentPage=" + currentPage +
                '}';
    }

    /**
     * 构造
     */
    public PageList() {
        this.setCurrentPage(1);
        this.setPerPage(10);
        this.setTotalNumber(0);
        this.setTotalPageNumber(0);
    }

    /**
     * 获取start，用于分页SQL语句LIMIT
     */
    public int getStart() {
        return (this.currentPage - 1) * this.perPage;
    }

}
